package com.esp.app.air;

import com.esp.app.widget.MyWidgetProvider;
import com.esp.app.widget.R;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.RemoteViews;


public class ViewAirPlaneHandler {
	
	private static final String TAG = ViewAirPlaneHandler.class.getName();
	
	public static void updateAppWidgets(final Context context,
			final AppWidgetManager appWidgetManager, final int[] appWidgetIds,
			final int resource) {

		Log.d(TAG, " ViewAirPlaneHandler|=> updateAppWidgets ");

		for (int i = 0; i < appWidgetIds.length; i++) {
			final int appWidgetId = appWidgetIds[i];
			updateAppWidget(context, appWidgetManager, appWidgetId, resource);
		}

	}
	
	public static void updateAppWidget(final Context context,
			final AppWidgetManager appWidgetManager, final int appWidgetId,
			final int resource) {

		Log.d(TAG, " ViewAirPlaneHandler|=> updateAppWidget ");

		final RemoteViews views = new RemoteViews(context.getPackageName(),
				R.layout.widget_layout);
		views.setImageViewResource(R.id.btn_airport,resource);
		
		final PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
				0, new Intent(MyWidgetProvider.TOGGLE_AIRPLANE_STATE),
				PendingIntent.FLAG_UPDATE_CURRENT);
		views.setOnClickPendingIntent(R.id.btn_airport, pendingIntent);
		appWidgetManager.updateAppWidget(appWidgetId, views);

	}
}
